# -*- coding: utf-8 *-*

#   This file is part of Sql-Rice.
#
#    Sql-Rice is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 3 of the License, or
#    (at your option) any later version.
#
#    Sql-Rice is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Sql-Rice; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA


import unittest
from tools.ricer import DSLRicer
from utils.temp_file import TempFile


class TestDSLRicer(unittest.TestCase):

    def test_conf_display(self):
        dsr = DSLRicer()
        dsr.parse_line('display form')
        self.assertTrue('display' in dsr.config)
        self.assertTrue(dsr.config['display'] == 'form')

    def test_load_ref(self):
        dsr = DSLRicer()
        with TempFile('select rut from tabla') as temp:
            dsr.parse_line('select ref "%s"' % temp.path)
        self.assertEquals(dsr.config['select'], 'select rut from tabla')

    def test_read_inline(self):
        dsr = DSLRicer()
        dsr.parse_line('select begin')
        dsr.parse_line('select rut, nombre, datos')
        dsr.parse_line('from tabla')
        dsr.parse_line('where rut=:rut;')
        dsr.parse_line('end')
        self.assertEquals(dsr.config['select'], 'select rut, nombre, ' +
                          'datos\nfrom tabla\nwhere rut=:rut;')

